local hx__bdcr = fk.CreateSkill {
  name = "hx__bdcr",
}


hx__bdcr:addEffect(fk.CardUseFinished, {
  anim_type = "special",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(hx__bdcr.name) and target then
      if target == player then
        return not table.contains(player:getTableMark("@$hx__AIDS"),data.card.name) and player:hasSkill("hx__AIDS",true)
      else
        return table.contains(player:getTableMark("@$hx__AIDS"),data.card.name)
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    if target == player then
      return player.room:askToSkillInvoke(player,{
        skill_name = hx__bdcr.name,
        prompt = "病毒传染：是否记录此 "..data.card:toLogString().." 的牌名进艾滋病中？",
      })
    else
      local max
      for _,p in ipairs(player.room.alive_players) do
        if p:hasSkill("hx__AIDS",true) then
          max = p:getMark("@hx__AIDS_num")
        end
      end
      local x = math.max(1,max)
      return player.room:askToSkillInvoke(player,{
        skill_name = hx__bdcr.name,
        prompt = "病毒传染：是否对 %dest 造成"..x.."点伤害并获得其"..x.."张牌？::"..target.id,
      })
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local max
    for _,p in ipairs(player.room.alive_players) do
      if p:hasSkill("hx__AIDS",true) then
        max = p:getMark("@hx__AIDS_num")
      end
    end
    local x = math.max(1,max)
    if target == player then
      room:addTableMarkIfNeed(player,"@$hx__AIDS",data.card.name)
    else
      room:damage{
        from = player,
        to = target,
        damage = x,
        skillName = hx__bdcr.name,
      }
      if #target:getCardIds("he") > 0 and not target.dead then
        local cards = room:askToChooseCards(player,{
          min = x,
          max = x,
          skill_name = hx__bdcr.name,
          target = target,
          flag = "he",
        })
        room:obtainCard(player, cards, false, fk.ReasonPrey, player, hx__bdcr.name)
      end
    end
  end,
})


return hx__bdcr
